<?php
//Linguaggio settato a 'und'
$lang = LANGUAGE_NONE;
//recupero il nid
$nid_node = $node->nid.uniqid();
//GET linguaggio
global $language;

switch ($view_mode) {
	case 'full':
?>
<div class="monoblocco">		
	<div class="contenuto">	
		<div class="galleria" id="nid_<?php print $nid_node; ?>">
		<?php if($language->language == 'it'):?>
			<?php if(isset($node->field_didascalia[$lang])):?>
			<div class="didascalia">
				<?php print $node->field_didascalia[$lang][0]['value']; ?>
			</div>
			<?php endif;?>
		<?php else: ?>
			<?php if(isset($node->field_didascalia_en[$lang])):?>
			<div class="didascalia">
				<?php print $node->field_didascalia_en[$lang][0]['value']; ?>
			</div>
			<?php endif;?>
		<?php endif;?>
			<div class="owl-carousel contenitore_galleria" id="<?php print $nid_node; ?>_galleria">	
				<?php foreach ($node->field_image[$lang] as $k => $img):?>											
				<div class="item elemento_galleria" id="elemento-galleria-<?php print $nid_node.'_'.($k+1); ?>">
					<div class="immagine">
						<img src="<?php print file_create_url($img['uri']);?>" />
					</div>
				</div>
				<?php endforeach;?>		
			</div>
			<!-- Pulsantiera Galleria -->					
			<div class="pulsanti_scorrimento" id="<?php print $nid_node; ?>_pulsanti_galleria">
				<a class="prev"><img src="<?php print base_path().path_to_theme(); ?>/images/previous_quadrato_w.png" /></a>
				<div class="conteggio_pagina">1/2</div>
				<a class="next"><img src="<?php print base_path().path_to_theme(); ?>/images/next_quadrato_w.png" /></a>
			</div>
			<script>
				numeroItem_<?php print $nid_node; ?> = $('#<?php print $nid_node; ?>_galleria .item.elemento_galleria').length;
				
				window.owl_<?php print $nid_node; ?> = $("#<?php print $nid_node; ?>_galleria"); // <?php print $nid_node; ?> Si tratta del nodo della galleria (NID)
				window.owl_<?php print $nid_node; ?>.owlCarousel({
					navigation:false,
					pagination: false,
					paginationNumbers: false,											
					addClassActive: true,
					paginationSpeed : 2500,
					goToFirstSpeed : 1000,
					singleItem : true,
					autoHeight : true,
					slideSpeed: 1000,
					mouseDrag: false,
					touchDrag: false,		
					afterMove: function(elem){
									divVisualizzato_<?php print $nid_node; ?> = $('#<?php print $nid_node; ?>_galleria .owl-item.active').find('div').attr('id');
									arr_<?php print $nid_node; ?> = divVisualizzato_<?php print $nid_node; ?>.split('_');
									$('#<?php print $nid_node; ?>_pulsanti_galleria .conteggio_pagina').html(arr_<?php print $nid_node; ?>[1]+'/'+numeroItem_<?php print $nid_node; ?>);
								}
				});									
				owl_<?php print $nid_node; ?>.ready(function(){
					  $('.owl-controls.clickable').hide();
					  $('.owl-controls').css('margin-top','0px');
				  });
				$('#<?php print $nid_node; ?>_pulsanti_galleria .conteggio_pagina').html('1/'+numeroItem_<?php print $nid_node; ?>);										  
				$('#<?php print $nid_node; ?>_pulsanti_galleria .next').click(function(){
					window.owl_<?php print $nid_node; ?>.trigger('owl.next');
				});
				
				$('#<?php print $nid_node; ?>_pulsanti_galleria .prev').click(function(){
					window.owl_<?php print $nid_node; ?>.trigger('owl.prev');
				});
				  
			</script>
		</div>
	</div>
</div>
<?php 	break;
	case 'teaser':
?>
<div class="galleria" id="nid_<?php print $nid_node; ?>">
<?php if($language->language == 'it'):?>
	<?php if($node->field_didascalia[$lang]):?>
	<div class="didascalia">
		<?php print $node->field_didascalia[$lang][0]['value']; ?>
	</div>
	<?php endif;?>
<?php else: ?>
	<?php if($node->field_didascalia_en[$lang]):?>
	<div class="didascalia">
		<?php print $node->field_didascalia_en[$lang][0]['value']; ?>
	</div>
	<?php endif;?>
<?php endif;?>
	<div class="owl-carousel contenitore_galleria" id="<?php print $nid_node; ?>_galleria">	
		<?php foreach ($node->field_image[$lang] as $k => $img):?>											
		<div class="item elemento_galleria" id="elemento-galleria-<?php print $nid_node.'_'.($k+1); ?>">
			<div class="immagine">
				<img src="<?php print file_create_url($img['uri']);?>" />
			</div>
		</div>
		<?php endforeach;?>		
	</div>
	<!-- Pulsantiera Galleria -->					
	<div class="pulsanti_scorrimento" id="<?php print $nid_node; ?>_pulsanti_galleria">
		<a class="prev"><img src="<?php print base_path().path_to_theme(); ?>/images/previous_quadrato_w.png" /></a>
		<div class="conteggio_pagina">1/2</div>
		<a class="next"><img src="<?php print base_path().path_to_theme(); ?>/images/next_quadrato_w.png" /></a>
	</div>
	<script>
		numeroItem_<?php print $nid_node; ?> = $('#<?php print $nid_node; ?>_galleria .item.elemento_galleria').length;
		
		window.owl_<?php print $nid_node; ?> = $("#<?php print $nid_node; ?>_galleria"); // <?php print $nid_node; ?> Si tratta del nodo della galleria (NID)
		window.owl_<?php print $nid_node; ?>.owlCarousel({
			navigation:false,
			pagination: false,
			paginationNumbers: false,											
			addClassActive: true,
			paginationSpeed : 2500,
			goToFirstSpeed : 1000,
			singleItem : true,
			autoHeight : true,
			slideSpeed: 1000,
			mouseDrag: false,
			touchDrag: false,		
			afterMove: function(elem){
							divVisualizzato_<?php print $nid_node; ?> = $('#<?php print $nid_node; ?>_galleria .owl-item.active').find('div').attr('id');
							arr_<?php print $nid_node; ?> = divVisualizzato_<?php print $nid_node; ?>.split('_');
							$('#<?php print $nid_node; ?>_pulsanti_galleria .conteggio_pagina').html(arr_<?php print $nid_node; ?>[1]+'/'+numeroItem_<?php print $nid_node; ?>);
						}
		});									
		owl_<?php print $nid_node; ?>.ready(function(){
			  $('.owl-controls.clickable').hide();
			  $('.owl-controls').css('margin-top','0px');
		  });
		$('#<?php print $nid_node; ?>_pulsanti_galleria .conteggio_pagina').html('1/'+numeroItem_<?php print $nid_node; ?>);										  
		$('#<?php print $nid_node; ?>_pulsanti_galleria .next').click(function(){
			window.owl_<?php print $nid_node; ?>.trigger('owl.next');
		});
		
		$('#<?php print $nid_node; ?>_pulsanti_galleria .prev').click(function(){
			window.owl_<?php print $nid_node; ?>.trigger('owl.prev');
		});
		  
	</script>
	</div>
<?php break;
}
?>